package cn.edu.lcvc.ebuy_23rj2.model.common;

public class ResponseData<T> {
    private Integer code;//http状态
    private Boolean success;//true成功
    private String msg;//提示2
    private T data;//返回数据

    public ResponseData(Integer code, Boolean success, String msg, T data) {
        this.code = code;
        this.success = success;
        this.msg = msg;
        if (data!=null){
            this.data=data;
        }else {
            this.data = (T)new String();
        }

    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    //成功业务
    public static <V> ResponseData success(V data){
        return new ResponseData(200,true,"操作成功",data);
    }

    public static <V> ResponseData success(){
        return new ResponseData(200,true,"操作成功",null);
    }

    public static <V> ResponseData error(String msg){
        return new ResponseData(200,false,msg,null);
    }

    public static <V> ResponseData error(Integer code,String msg){
        return new ResponseData(401,false,msg,null);
    }
}
